package org.jimmy.tang.ssl;

/**
 * @author jimmy
 * 
 */
public class TwoWayHttpsURLConnectionDemo {

    // 客户端密钥库
    private String sslKeyStorePath;
    private String sslKeyStorePassword;
    private String sslKeyStoreType;
    // 客户端信任的证书
    private String sslTrustStore;
    private String sslTrustStorePassword;
    private String eaiUrl;

    // 初始化数据
    public TwoWayHttpsURLConnectionDemo() {
        sslKeyStorePath = "D:/ssl/clientKeys.jks";
        sslKeyStorePassword = "123456";
        sslKeyStoreType = "JKS"; // 密钥库类型，有JKS PKCS12等
        sslTrustStore = "D:/ssl/clientTrust.jks";
        sslTrustStorePassword = "123456";
        eaiUrl = "https://test.yihaodian.com:8443/ims/feedbackToPingAn_getData.action";
    }

    public String sendData(String data) {
        String receivedData = null;
        try {

            System.setProperty("javax.net.ssl.keyStore", sslKeyStorePath);
            System.setProperty("javax.net.ssl.keyStorePassword",
                    sslKeyStorePassword);
            System.setProperty("javax.net.ssl.keyStoreType", sslKeyStoreType);
            // 设置系统参数
            System.setProperty("javax.net.ssl.trustStore", sslTrustStore);
            System.setProperty("javax.net.ssl.trustStorePassword",
                    sslTrustStorePassword);
            receivedData = send(eaiUrl, data);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return receivedData;
    }

    public static String send(String sendurl, String sendData) throws Exception {
        // 和OneWayHttpsConnectionDemo 一样
        return null;
    }

    public static void main(String[] args) {
        TwoWayHttpsURLConnectionDemo t = new TwoWayHttpsURLConnectionDemo();
        t.sendData("测试SSL双项连接，向服务端发送数据!");
    }
}
